package org.sucri.floxs.html;

import org.sucri.dao.NewsEntity;

import java.sql.Timestamp;
import java.text.FieldPosition;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Wen Yu
 * Date: Sep 2, 2007
 * Time: 1:53:21 PM
 * To change this template use File | Settings | File Templates.
 */
public class Entity2Html_Factory
{
  public static StringBuffer toDateBox(Timestamp t, StringBuffer buf)
  {
    if (buf == null) buf = new StringBuffer();

    SimpleDateFormat df = new SimpleDateFormat();

    buf.append("<div class='date_box'><div class='date_box_month'>");
    buf = df.format(t, buf, new FieldPosition(0));
    buf.append("</div><div class='date_box_day'>");
    buf = df.format(t, buf, new FieldPosition(1));
    buf.append("</div>");

    return buf;
  }
  public static StringBuffer toNewsClip(NewsEntity news, StringBuffer buf)
  {
    if (buf == null) buf = new StringBuffer();

    buf.append(toDateBox(news.getLastmodifyDate(), buf));
    buf.append("<h3>");
    buf.append(news.getTitle());
    buf.append("</h3>");
    buf.append("<p>");
    buf.append(news.getContents());
    buf.append("</p>\n");

    return buf;
  }
  public static StringBuffer toNewsClip(List<NewsEntity> news, StringBuffer buf)
  {
    if (buf == null) buf = new StringBuffer();

    for (NewsEntity N : news) buf = toNewsClip(N, buf);

    return buf;
  }
}
